<?php


namespace App\Controller\Admin;


use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Request\Admin\UserWithDrawExportRequest;
use App\Request\Admin\UserWithDrawRejectRequest;
use App\Service\Admin\UserWithDrawService;
use Hyperf\Di\Annotation\Inject;

class UserWithDrawController extends AbstractController
{

    /**
     * @Inject()
     * @var UserWithDrawService
     */
    protected $userWithDrawService;

    /**
     * @OperationLog(event="获取提现列表",platform="admin")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function index()
    {
        $where = $this->request->query();
        $index = $this->userWithDrawService->index($where);
        return $this->response->success($index);
    }

    /**
     * @OperationLog(event="提现打款",platform="admin")
     * @param int $userWithDrawId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     * @throws \Exception
     */
    public function transfer(int $userWithDrawId)
    {
        $this->userWithDrawService->transfer($userWithDrawId);
        return $this->response->success();
    }

    /**
     * @OperationLog(event="驳回提现",platform="admin")
     * @param int $userWithDrawId
     * @param UserWithDrawRejectRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function reject(int $userWithDrawId, UserWithDrawRejectRequest $request)
    {
        $validated = $request->validated();
        $this->userWithDrawService->reject($userWithDrawId, $validated['message']);
        return $this->response->success();
    }

    /**
     * @OperationLog(event="确认体现",platform="admin")
     * @param int $userWithDrawId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function confirm(int $userWithDrawId)
    {
        $this->userWithDrawService->confirm($userWithDrawId);
        return $this->response->success();
    }

    /**
     * 用户提现流水
     * @OperationLog(event="用户提现流水",platform="admin")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function userWithDrawLogs()
    {
        $where = $this->request->query();
        $index = $this->userWithDrawService->userWithDrawLogs($where);
        return $this->response->success($index);
    }


    /**
     * 用户提现流水导出
     * @param UserWithDrawExportRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
    public function userWithDrawExport(UserWithDrawExportRequest $request)
    {
        $validated = $request->validated();
        return $this->userWithDrawService->userWithDrawExport($validated);
    }
}